package com.lwx.png;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;


public class PngMain {
    public static void main(String[] args) throws Exception {
        File file = new File("C:\\Users\\think\\Desktop\\images\\");
        for(File f : file.listFiles()){
            decode(f);
        }
    }
    
    public static void decode(File f) throws Exception{
        FileInputStream in = new FileInputStream(f);
        int b;
        boolean pipei = false;
        boolean first = true;
        FileOutputStream out = new FileOutputStream(
                new File("C:\\Users\\think\\Desktop\\images\\" + f.getName() + ".png"));
        while((b = in.read()) != -1){
            if(pipei || (b == 0x89 && in.read() == 0x50 && in.read() == 0x4e)){
                pipei = true;
                if(first){
                    out.write(0x89);
                    out.write(0x50);
                    out.write(0x4e);
                    first = false;
                }else{
                    out.write(b);
                }
            }
        }
        
        out.close();
    }
}
